import numpy
from tensorflow.keras import models, Model
from tensorflow.keras.utils import plot_model
import tensorflow as tf
from icecream import ic

from data_pre import datasets
from utils.coding import encode, decode, get_z


def predict():
    x_train, y_train, x_test, y_test = datasets.read_data()

    model: Model = models.load_model('cnn_best.h5')

    true_num = 0
    for i in range(1000):
        x_demo = tf.reshape(x_test[i], (1, 30, 120))
        y_demo = y_test[i]

        y_pre = model.predict(x_demo)

        for j in range(len(y_pre)):
            y_pre[j] = numpy.argmax(y_pre[j])
            y_demo[j] = numpy.argmax(y_demo[j])

        y_ori = []
        for k in y_demo:
            y_ori.append(k[0])

        if y_ori == y_pre:
            true_num += 1
        else:
            ic(decode(y_pre), decode(y_ori))

    ic(true_num / 1000 * 100)


if __name__ == '__main__':
    predict()
